package com.hmall.item.config;

import com.hmall.common.utils.BaseContext;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
//@Configuration
@Slf4j
public  class ItemInterceptor implements HandlerInterceptor {
        public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
            log.debug("preHandle...");
            String authorization = request.getHeader("authorization");
            log.info("authorization: {}",authorization);
            BaseContext.setThreadLocal(Long.parseLong(authorization));
//            String username = request.getParameter("username");
//            if (!"admin".equals(username)) {
//                log.debug("拦截...");
//                throw new RuntimeException("没有权限执行此操作，请重新登录");
//            }
            log.debug("放行...");
            return true;
        }
    }